/* Global styles and reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    overflow: hidden;
    user-select: none;
}

/* Main container - responsive height based on context */
.sequencer-container {
    width: 100%;
    height: 450px;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    background: linear-gradient(135deg, #0f3460 0%, #16213e 100%);
}

/* When opened in new tab, use more vertical space */
@media (min-height: 600px) {
    .sequencer-container {
        height: 90vh;
    }
}

/* Transport controls section */
.transport-section {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    flex-shrink: 0;
}

.transport-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.transport-btn.play {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
    color: white;
}

.transport-btn.play.playing {
    background: linear-gradient(135deg, #ff6b6b 0%, #cc5555 100%);
}

.transport-btn.stop {
    background: linear-gradient(135deg, #666 0%, #444 100%);
    color: white;
}

.transport-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.transport-btn:active {
    transform: translateY(0);
}

.tempo-control, .swing-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tempo-control label, .swing-control label {
    font-size: 12px;
    font-weight: bold;
    min-width: 35px;
}

.tempo-control input, .swing-control input {
    width: 100px;
    height: 6px;
    cursor: pointer;
}

.tempo-control span, .swing-control span {
    font-size: 14px;
    font-weight: bold;
    min-width: 35px;
    color: #00d4ff;
}

/* Sequencer grid section */
.sequencer-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

/* Step indicators */
.step-indicators {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
    flex-shrink: 0;
}

.track-label-spacer {
    width: 80px;
    flex-shrink: 0;
}

.steps-container {
    flex: 1;
    display: flex;
}

.step-numbers {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 2px;
    width: 100%;
}

.step-number {
    text-align: center;
    font-size: 10px;
    color: #888;
    padding: 2px;
}

/* Tracks container */
#tracksContainer {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Individual track row */
.track-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 4px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    transition: background 0.2s;
}

.track-row.selected {
    background: rgba(0, 212, 255, 0.2);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

/* Track label and controls */
.track-label {
    width: 80px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.track-name {
    font-size: 11px;
    font-weight: bold;
    color: #00d4ff;
    cursor: pointer;
    padding: 4px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    text-align: center;
    transition: all 0.2s;
}

.track-name:hover {
    background: rgba(0, 212, 255, 0.2);
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 4px;
}

.volume-control input {
    width: 100%;
    height: 4px;
}

.volume-value {
    font-size: 9px;
    color: #888;
    min-width: 25px;
}

/* Step buttons grid */
.steps {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 2px;
}

.step {
    aspect-ratio: 1;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    min-height: 24px;
}

/* Step states */
.step:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(0, 212, 255, 0.5);
    transform: scale(1.05);
}

.step.active {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
    border-color: #00d4ff;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.step.playing {
    animation: pulse 0.2s ease-out;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
}

.step.current {
    border-color: #ffff00;
    border-width: 3px;
}

/* Velocity indicator on active steps */
.step.active::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 3px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 2px;
}

/* Pulse animation for playing steps */
@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Controls panel at bottom */
.controls-panel {
    display: flex;
    gap: 10px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* Pattern controls */
.pattern-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.control-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, #444 0%, #222 100%);
    color: white;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
    height: fit-content;
}

.control-btn:hover {
    background: linear-gradient(135deg, #555 0%, #333 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.control-btn:active {
    transform: translateY(0);
}

#presetSelect {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 12px;
    cursor: pointer;
    height: fit-content;
}

/* Filter section */
.filter-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    min-width: 200px;
}

.filter-header {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #888;
}

.filter-header span:first-child {
    font-weight: bold;
    color: #00d4ff;
}

.filter-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.filter-knob-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.filter-knob-container label {
    font-size: 11px;
    font-weight: bold;
    color: #00d4ff;
}

.knob-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

/* Rotary knob styling */
.knob {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #333, #111);
    border: 3px solid #444;
    position: relative;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5), inset 0 2px 5px rgba(255, 255, 255, 0.1);
    transition: border-color 0.2s;
}

.knob:hover {
    border-color: #00d4ff;
}

.knob-indicator {
    position: absolute;
    width: 4px;
    height: 20px;
    background: #00d4ff;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 2px;
    box-shadow: 0 0 5px rgba(0, 212, 255, 0.8);
}

.knob-value {
    font-size: 11px;
    color: #00d4ff;
    font-weight: bold;
}

/* Tooltip styling */
.tooltip {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 1000;
    max-width: 300px;
    text-align: center;
    border: 2px solid #00d4ff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.tooltip.show {
    opacity: 1;
}

/* Scrollbar styling */
.sequencer-grid::-webkit-scrollbar {
    width: 8px;
}

.sequencer-grid::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.sequencer-grid::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.5);
    border-radius: 4px;
}

.sequencer-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 212, 255, 0.7);
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    .transport-section {
        flex-wrap: wrap;
    }
    
    .controls-panel {
        flex-direction: column;
    }
    
    .filter-section {
        min-width: 100%;
    }
}